home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / datetime.zip / SETTIME.ASM < prev    next >
Assembly Source File  |  1988-09-29  |  8KB  |  157 lines

  1. title    SETTIME.ASM
  2. page     ,132
  3. ;*****************************************************************************
  4. ;* Program Name | SETTIME.ASM                                                *
  5. ;*       Author | Gregory B. Besch                                           *
  6. ;*      Created | 9/29/1988 at 22:41                                         *
  7. ;*      Purpose | Set the computer's system time.                            *
  8. ;*       Syntax | expL = settime(expC)                                       *
  9. ;*              | where: expC is the time to set, in the same format         *
  10. ;*              |        returned by Clipper's time() function.              *
  11. ;*              |                                                            *
  12. ;*      Example | error = settime("22:41:01")                                *
  13. ;*      Returns | expL  - .f. = no error, time changed successfully.         *
  14. ;*              |         .t. = error encountered, time not changed.         *
  15. ;*              |                                                            *
  16. ;*      Version | Clipper Summer '87                                         *
  17. ;*     Revision | 1.0    Last Revised: 9/29/1988  @ 22:41                    *
  18. ;* ------------------------------------------------------------------------- *
  19. ;*   Copyright (C) 1988 by Gregory B. Besch                                  *
  20. ;*   Released to the public domain 9/30/88.                                  *
  21. ;*****************************************************************************
  22.  
  23. public   SETTIME
  24.  
  25. extrn    __PARINFO:far                             ; Clipper's Parm Info Svc
  26. extrn    __PARC:far                                ; Clipper's Char 'getter'
  27. extrn    __RETL:far                                ; Clipper's Logical return
  28.  
  29. ; =======[ EQUATES ]======================================================== ;
  30.          UNDEFINED      EQU   0
  31.          CHARACTER      EQU   1
  32.          NUMERIC        EQU   2
  33.          LOGICAL        EQU   4
  34.          DATE           EQU   8
  35.          BY_REFERENCE   EQU   32
  36.          MEMO           EQU   65
  37.  
  38. ; =======[ DATA ]=========================================================== ;
  39. DGROUP   GROUP    DATASG                           ; Clipper's Data Segment
  40.          DATASG   SEGMENT   PUBLIC    '_DATA'
  41.  
  42.          ; ----------------------------------------------------------------- ;
  43.          ; Storage                                                           ;
  44.          ; ----------------------------------------------------------------- ;
  45.          SYSTIME        db    8 dup(0)
  46.          SYSHRS         db    0
  47.          SYSMIN         db    0
  48.          SYSSEC         db    0
  49.  
  50. DATASG   ENDS
  51.  
  52.  
  53. ; =======[ CODE ]=========================================================== ;
  54. ;
  55. _PROG    SEGMENT  BYTE  'CODE'
  56.          ASSUME   CS:_PROG,DS:DGROUP
  57.  
  58. SETTIME  PROC     FAR
  59.          ; ----------------------------------------------------------------- ;
  60.          ; Save registers                                                    ;
  61.          ; ----------------------------------------------------------------- ;
  62.          push     bp
  63.          mov      bp,sp                   ; Establish addressability to stack
  64.          push     ds
  65.          push     es
  66.          push     si
  67.          push     di
  68.  
  69.          ; ----------------------------------------------------------------- ;
  70.          ; Get parameters                                                    ;
  71.          ; ----------------------------------------------------------------- ;
  72. ;---------------------
  73. ;  Debugger breakpoint
  74. ;         db       0CCh
  75. ;---------------------
  76. Parm1:   mov      ax,1                    ; parm number 1:  Time
  77.          push     ax                      ; pass to ParInfo on stack
  78.          call     __PARINFO               ; ask ParInfo what type
  79.          add      sp,2                    ; restore stack
  80.          cmp      ax,CHARACTER            ; is 1st parm Character?
  81.          je       Get1st                  ; if so, press on
  82.          mov      ax,1                    ; if not, set ax = .t.
  83.          jmp      Exit                    ;  and exit
  84. Get1st:  mov      ax,1                    ; 1st parm:  Time
  85.          push     ax                      ; pass to ParInfo on stack
  86.          call     __PARC                  ; call Clipper's character getter
  87.          add      sp,2                    ; restore stack
  88.  
  89. xsetup:  push     ds                      ; save data seg
  90.          mov      ds,dx                   ; transfer string segment ptr to es
  91.          mov      si,ax                   ; transfer string offset ptr to di
  92.          pop      es                      ; load data segment into es
  93.          lea      di,SYSTIME              ; load variable offset into di
  94.          mov      cx,8                    ; cx = 8 byte string size
  95.          cld
  96. xfer:    rep      movsb                   ; move system date
  97.  
  98. convert: push     es                      ; transfer data segment back to ds
  99.          pop      ds                      ;  via stack
  100.          lea      si,SYSTIME              ; point es:si to SYSTIME
  101.          mov      cx,2                    ; count = 2 bytes for hour
  102.          mov      dx,0                    ; starting value of zero
  103.          call     DEC2BIN                 ; convert hour to binary
  104.          mov      [SYSHRS],dl             ; save converted hour
  105.          inc      si                      ; bump si past colon separator
  106.          mov      cx,2                    ; count = 2 bytes for minutes
  107.          mov      dx,0                    ; starting value of zero
  108.          call     DEC2BIN                 ; convert minutes to binary
  109.          mov      [SYSMIN],dl             ; save converted minutes
  110.          inc      si                      ; bump si past colon separator
  111.          mov      cx,2                    ; count = 2 bytes for seconds
  112.          mov      dx,0                    ; starting value of zero
  113.          call     DEC2BIN                 ; convert seconds to binary
  114.          mov      [SYSSEC],dl             ; save converted seconds
  115.          
  116. timeset: mov      ah,2Dh                  ; DOS Set Time service
  117.          mov      ch,[SYSHRS]             ; system hour
  118.          mov      cl,[SYSMIN]             ; system minutes
  119.          mov      dh,[SYSSEC]             ; system seconds
  120.          mov      dl,0                    ; hundredths of seconds
  121.          int      21h                     ; call DOS to set time
  122.          mov      ah,0                    ; zero ah for return
  123.  
  124. exit:    pop      di                      ; restore registers
  125.          pop      si
  126.          pop      es
  127.          pop      ds
  128.          pop      bp
  129.  
  130.          push     ax                      ; push return code on stack
  131.          call     __RETL                  ; and return it to clipper
  132.          add      sp,2                    ; restore stack
  133.          ret                              ; bye bye
  134.  
  135. DEC2BIN  PROC     NEAR
  136. GetDigit:push     cx
  137.          lodsb                            ; Get a digit
  138.          sub      al,30h                  ; convert to binary
  139.          cbw                              ; convert to word
  140.          push     ax                      ; save it temporarily
  141.          mov      ax,dx                   ; get current value
  142.          mov      cx,10                   ; multiplier
  143.          mul      cx                      ; adjust for place value
  144.          mov      dx,ax                   ; move it back to dx
  145.          pop      ax                      ; retrieve current digit
  146.          add      dx,ax                   ; add it to cumulative value
  147.          pop      cx                      ; restore digit count
  148.          loop     GetDigit                ; and get next digit
  149.          ret
  150. DEC2BIN  ENDP
  151.  
  152. SETTIME  ENDP
  153.  
  154. _PROG    ENDS                             ; End of segment
  155.          END
  156.  
  157.